<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { statisticsApi } from "@/api/controller";
  import configForm from './configForm.vue';
  const configFormRef = ref()
  const action = reactive({
    list:[] as Array<any>
  })
  const handleForm = (row:any = {})=>{
    configFormRef.value.openDialog(row)
  }
  const getConfigInfo = async()=>{
    const res = await statisticsApi.familyconfig()
    const {
      stake=[], maxPrice=0, rewardMin=0,
      rewardMax=0, screenMin=0, profitRate=0
    } = res?.data || {}
    action.list = [
      {id:1,text:'参与配置',integral:stake,key:'stakeText'},
      {id:2,text:'整体参与金豆数',integral:maxPrice,key:'maxPrice'},
      {id:3,text:'下限值',integral:rewardMin,key:'rewardMin'},
      {id:4,text:'上限值',integral:rewardMax,key:'rewardMax'},
      {id:5,text:'飘屏通知下限值',integral:screenMin,key:'screenMin'},
      {id:6,text:'利润率',integral:profitRate,key:'profitRate'},
    ]
  }
  onMounted(()=>{
    getConfigInfo()
  })
</script>

<template>
  <div class="xm-content">
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column min-width="120" prop="text" label="配置名称" />
      <el-table-column min-width="120" prop="integral" label="配置内容">
        <template #default="scope">
          <template v-if="scope.row.id == 1">
            <div v-for="item in scope.row.integral">
              参与区{{ item.id }}：{{ item.price }}金豆
            </div>
          </template>
          <template v-else-if="scope.row.id == 6">{{ scope.row.integral }}%</template>
          <template v-else>{{ scope.row.integral }}</template>
        </template>
      </el-table-column>
      <el-table-column width="180" fixed=right label="操作">
        <template #default="scope">
          <el-button type="primary" @click="handleForm(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <configForm ref="configFormRef" @update-list="getConfigInfo" />
  </div>
</template>

<style lang='scss' scoped>

</style>
